package com.zwy.leetcode;

import java.util.*;

public class Day07Test {
    /**
     * 14. 最长公共前缀
     * @param strs
     * @return
     */
    public String longestCommonPrefix(String[] strs) {
        if(strs.length==1)return strs[0];
        List<Character> list=new LinkedList<Character>();
        int min=strs[0].length();
        for (int i = 0; i <strs[0].length() ; i++) {
            list.add(strs[0].charAt(i));
        }
        for (int i = 1; i <strs.length ; i++) {
            int t=strs[i].length();
            int len=Math.min( strs[0].length(),strs[i].length());
            for (int j = 0; j < len; j++) {
                if(strs[i].charAt(j)==list.get(j))continue;
                 t=j;
                 break;
            }
            min=Math.min(t,min);
        }
        return strs[0].substring(0,min);
    }
    public void rotate(int[] nums, int k) {
        if(nums.length==1)return;
        while(k>nums.length){
            k-=nums.length;
        }
        int []p=new int[nums.length];
        for (int i = 0; i <nums.length ; i++) {
            p[i]=nums[i];
        }
        for (int i = k; i < nums.length; i++) {
            nums[i]=p[i-k];
        }
        for (int i = 0; i < k; i++) {
            nums[i]=p[i+nums.length-k];
        }
    }
    public static void main(String[] args) {
        int []nums = {1,2};
        int k = 3;
        Day07Test day07Test=new Day07Test();
         day07Test.rotate(nums,k);
        System.out.println(nums);
    }
}
